﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class RepairBoxes :_RepairBoxes
    {
        public static string GetBoxName(int id)
        {
            try
            {
                RepairBoxes box = new RepairBoxes();
                box.Where.ID.Value = id;
                box.Query.AddResultColumn(RepairBoxes.ColumnNames.RepairBoxName);
                box.Query.Load();

                return box.s_RepairBoxName;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("RepairBoxes.cs", "GetBoxName", ex.StackTrace);
                throw ex;
            }
        }

        public static void DeleteBoxes(string ids)
        {
            try
            {
                RepairBoxes box = new RepairBoxes();
                box.Where.ID.Value = ids.Replace(")", "").Replace("(", "");
                box.Where.ID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.In;
                box.Query.Load();
                for (int i = 0; i < box.RowCount; i++)
                {
                    box.Deleted = true;
                    box.MoveNext();
                }
                box.Save();
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("RepairBoxes.cs", "DeleteBoxes", ex.StackTrace);
                throw ex;
            }
        }

        public static void UpdateStatus(int id, bool free)
        {
            try
            {
                RepairBoxes box = new RepairBoxes();
                box.Where.ID.Value = id;
                box.Query.Load();
                if (box.RowCount > 0 && box.IsFree != free)
                {
                    box.IsFree = free;
                    box.Save();
                }
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("RepairBoxes.cs", "DeleteBoxes", ex.StackTrace);
                throw ex;
            }
        }
    }
}
